package datastrucure.tree;

import java.util.*;

/**
 * @Author Fizz Pu
 * @Date 2021/3/16 下午2:45
 * @Version 1.0
 * 失之毫厘，缪之千里！
 */
public class MinHeap {
    public static void main(String[] args) {
        MinHeap heap = new MinHeap(Arrays.asList(1,2,3));
    }

    public MinHeap(List<Integer> arr) {
        if(arr == null || arr.size() == 0){
            throw  new IllegalArgumentException("arr != null || arr.length != 0");
        }
        this.arr = arr;
    }

    // 完全二叉树存储数组
    private List<Integer> arr;

    // 构建
    public void build(){

    }

    // 插入
    public void insert(int val){
        arr.add(val);
        // 上浮
        int childIndex = arr.size() - 1;
        while (childIndex >= 0){
            int parentIndex = (childIndex  - 1 )/ 2;
            int chidlVal = arr.get(childIndex);
            int parentVal = arr.get(parentIndex);
            if(parentIndex < chidlVal){
                arr.set(parentIndex, chidlVal);
                arr.set(childIndex, parentVal);
                childIndex = parentIndex;
            } else {
                break;
            }
        }
    }

    // 删除
    public void remove(){
        arr.set(0, arr.get(arr.size() - 1));
        arr.remove(arr.size() - 1);
        // 向下调整
        int parIndex = 0;
        int leftIndex;
        int rightIndex;
    }

    // 修改
    public void update(){

    }

    // 查找
    public int search(){
        return -1;
    }
}
